const getUrlQuery = require('./../utils/url');
const { verifyToken } = require('./../utils/token');

module.exports = async (req, res, next) => {
  console.log(req.body, '===中间件>>>', req.headers.token);
  req.user = {
    id: 1,
    name: 'hello',
  }
  next();
  // const token = req.headers.token || getUrlQuery(req.url, 'token');
  // if (!token) {
  //   return res.json({ code: 1, message: '请输入token' });
  // } else {
  //   try {
  //     const user = await verifyToken(token);
  //     if (user) {
  //       req.user = user;
  //       next();
  //     } else {
  //       return res.json({ code: 1, message: '输入的token不合法' });
  //     }
  //   } catch(e) {
  //     return res.json({ code: 1, message: '输入的token不合法' });
  //   }
  // }
}